package cn.lf.android.lawfirm.upgrade.approval.controler;


import android.content.Context;

import com.alibaba.fastjson.JSON;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import cn.lf.android.lawfirm.AppConfig;
import cn.lf.android.lawfirm.BaseController;
import cn.lf.android.lawfirm.http.manager.EBCallback;
import cn.lf.android.lawfirm.http.manager.MyOkHttpClient;
import cn.lf.android.lawfirm.undertake.approval.modle.LawyerFeeInfo;
import cn.lf.android.lawfirm.utils.DebugLog;
import cn.lf.android.lawfirm.utils.SPUtil;

public class UpgradeLawyerFeeInfoController extends BaseController{
    FeeInfoCallback mFeeInfoCallback;
    private Context context;

    public UpgradeLawyerFeeInfoController(FeeInfoCallback callback, Context context) {
        this.mFeeInfoCallback = callback;
        this.context = context;
    }

    /**
     * @param relationSid
     */
    public void onFeeInfo(String relationSid) {
        showProgressDia(context);
        Map<String, String> params = new HashMap<String, String>();
        SPUtil spUtil = new SPUtil(context);
        params.put("SID", relationSid);
        params.put("Authorization", spUtil.getAccessToken());
        DebugLog.e("relationSid=666=" + relationSid);
        DebugLog.e("Authorization=666=" + spUtil.getAccessToken());
        new MyOkHttpClient().doGet(AppConfig.LSCaseApproveRecordList_NewCaseLevel_ChargeInfo, params,
                new EBCallback() {
                    @Override
                    public void onEBResponse(String response) {
                        DebugLog.e("费用="+response);
                        JSONObject myJsonObject;
                        JSONObject responsObject;
                        Boolean isSuc;
                        String arraylist;
                        try {
                            myJsonObject = new JSONObject(response);
                            isSuc = myJsonObject.getBoolean("isSuc");
                            if (isSuc) {
                                responsObject = myJsonObject.getJSONObject("responsObject");
                                LawyerFeeInfo bean = JSON.parseObject(responsObject.toString(), LawyerFeeInfo.class);
                                mFeeInfoCallback.onFeeInfouccessed(bean);
                            } else {
                                mFeeInfoCallback
                                        .onFeeInfoFailed();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        dismissProgressDia();
                    }

                    @Override
                    public void onEBError(String errorMsg) {
                        mFeeInfoCallback.onFeeInfoFailed();
                        dismissProgressDia();
                    }
                },"Authorization",spUtil.getAccessToken());
    }

    public interface FeeInfoCallback {
        public void onFeeInfouccessed(LawyerFeeInfo beans);

        public void onFeeInfoFailed();

    }

}
